package com.darkevil.descan.util

import java.io.File

/**
 * Created by DaRKeViL on 2017/7/21.
 */
class DiskUtil {
    //静态方法要用companion object扩起来
    companion object {
        /**
         * 获取驱动器类型
         * @param drive 驱动器路径
         */
        fun getDriveType(drive: String): String {
            return CMDUtil.runcmd("fsutil fsinfo driveType " + drive)
        }

        /**
         * 判断是否是u盘
         * @param drive 驱动器路径
         */
        fun isUPan(drive: String): Boolean {
            val driveType = getDriveType(drive)
            println(driveType)
            return driveType.contains("可移动")

        }

        /**
         * 删除所有文件
         * @param drive 驱动器路径
         */
        fun removeAllFile(drive: String): String {
            println("删除" + drive + "下所有文件")
            return CMDUtil.runcmd("cmd /c rd /s /q " + drive)
        }

        /**
         * 判断驱动器是否是空的
         * @param drive 驱动器路径
         */
        fun isEmptyDrive(drive: File): Boolean {
            //如果文件数为0，则认为是空的
            return drive.list().size == 0
        }

        /**
         * 判断是否忽略该驱动器
         * @param drive 驱动器路径
         */
        var IGNORE_TAG_FILENAME="dedescan"
        fun isIgnoreDrive(drive: File): Boolean {
            drive.listFiles()
                    .filter { it.name.toLowerCase().equals(IGNORE_TAG_FILENAME.toLowerCase()) }
                    .forEach {
                        println("发现忽略标记文件=>"+ IGNORE_TAG_FILENAME)
                        return true }
            return false
        }

    }
}